import { defineStore } from 'pinia'
import { service } from '../request/index.js'
import { log } from '../utils/log.js'

export const useCommonStore = defineStore('common', {
  state: () => {
    return {
      visibleLoginDialog: false,
      version: ''
    }
  },
  actions: {
    showLoginDialog() {
      this.visibleLoginDialog = true
    },
    closeLoginDialog() {
      this.visibleLoginDialog = false
    },
    async getVersion() {
      try {
        const { data } = await service.get('/version')
        if (data.ok) {
          this.version = data.result
          return data.result
        }
      } catch (error) {
        log(error)
      }
    }
  },
  getters: {}
})
